package com.kgc.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.kgc.entity.Brand;
import com.kgc.entity.BrandExample;
import com.kgc.mapper.BrandMapper;
import com.kgc.service.BrandService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class BrandServiceImpl implements BrandService {
    @Autowired
    private BrandMapper brandMapper;

    public Brand findBrandById(Integer id) {
        return brandMapper.selectByPrimaryKey(id);
    }

    public PageInfo<Brand> showPageOfBrand(Brand brand, Integer pageNum, Integer pageSize) {
        BrandExample brandExample = new BrandExample();
        BrandExample.Criteria criteria = brandExample.createCriteria();
        if (brand!=null && brand.getName()!=null && !"".equals(brand.getName())){
            criteria.andNameLike("%"+brand.getName()+"%");
        }
//        if (brand!=null && brand..getPrice()!=null && !"".equals(clothes.getPrice())){
//            criteria.andPriceEqualTo(clothes.getPrice());
//        }
        PageHelper.startPage(pageNum,pageSize);
        return new PageInfo<Brand>(brandMapper.selectByExample(brandExample));
    }

    public Integer addBrand(Brand brand) {
        return brandMapper.insertSelective(brand);
    }

    public Integer removeBrandById(Integer id) {
        return brandMapper.deleteByPrimaryKey(id);
    }

    public Integer alterBrand(Brand brand) {
        return brandMapper.updateByPrimaryKeySelective(brand);
    }
}
